<?php

namespace App\Services\ExchangeBalance;

use App\Models\User;
use Carbon\Carbon;
use App\Http\Controllers\Api\V1\Requests\FormRequest;

class ExchangeBalanceRequest extends FormRequest
{
	public function rules()
	{
		return [
			'apples' => [
				'required',
				'integer',
				'min:1',
				$this->appleNumbers(),
			],
		];
	}

	public function appleNumbers()
	{
		return function ($key, $value, $fail) {

			$user = $this->user();

			if (big_decimal($user->apples)->isLessThan($value)) {
				return $fail('用户苹果数量不足');
			} 

			return true;
		};
	}

}
